function msg = decode_wrapper(infile, k, seed)
%DECODE_WRAPPER decode message from JPEG files.
%  MSG = DECODE_WRAPPER(INFILE, K, SEED)
%  The input argument INFILE specify the name of JPEG file to read. K is
%  the number of bits of message in each loop. SEED is a integer number to 
%  initialize the random sequence, and function as a key.
%  The output MSG is the text decoded from the image.
%  The default value for K is 2, SEED is the size of the input image.
    if nargin < 1
        error('Wrong number of arguments.');
    end
    if nargin < 2
        k = 2;
    end
    jobj = jpeg_read(infile);
    coef = jobj.coef_arrays{1};    
    M = jobj.image_height;
    N = jobj.image_width;
    if nargin < 3
        seed = M*N;
    end
    rands = getRandStream(seed);
    fprintf(1,'decode argument: k = %d, seed = %d\n',k,seed);
    tic;
    msg = decodeimage(coef, k, rands);
    toc;
end
